package org.tony.spider.common;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 抽象上下文类，用于其他上下文类继承
 *
 */
public abstract class AbstractContext<K, V>
{
  protected ConcurrentHashMap<K, V> context;

  public V get(K key)
  {
    return context.get(key);
  }

  public V put(K key, V value)
  {
    if (context.contains(key))
    {
      context.remove(key);
    }
    return context.put(key, value);
  }

  public V remove(K key)
  {
    return context.remove(key);
  }

  public ConcurrentMap<K, V> getContext()
  {
    return context;
  }
}
